package com.twelve.controller.faker;

import com.github.javafaker.Faker;
import com.twelve.bean.faker.WarehouseHistory;
import com.twelve.utils.JqgridUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 * @program: twelve
 * @description: 库存历史
 * @author: geyuqi
 * @create: 2018-11-24 10:35
 **/

@Controller
@RequestMapping("/warehouseHistory")
public class WarehouseHistoryController {

    private Faker faker = new Faker(Locale.CHINA);

    @Resource
    private JqgridUtil jqgridUtil;

    /**
     * 跳转页面
     * @param request
     * @return
     */
    @RequestMapping("")
    public String recently(HttpServletRequest request){
        return "faker/warehouseHistory";
    }

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd  HH:mm:ss");

    /**
     * 库存历史列表
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("list")
    public String list(HttpServletRequest request){
        String pageNo = request.getParameter("page"); // 取得当前页数,注意这是jqgrid自身的参数
        String pageSize = request.getParameter("rows"); // 取得每页显示行数，,注意这是jqgrid自身的参数

        List<WarehouseHistory> list = new ArrayList<WarehouseHistory>();
        for (int i = 0; i < 10; i++) {
            WarehouseHistory warehouseHistory = new WarehouseHistory();
            warehouseHistory.setDate(simpleDateFormat.format(new Date()));
            warehouseHistory.setOpt(i%2==0?"出":"入");
            warehouseHistory.setRemark("备注");
            warehouseHistory.setWarehouseMan(faker.name().name());
            if(i==0){
                warehouseHistory.setCargoName("高压胶鞋");
                warehouseHistory.setCategoryName("劳保用品");
                warehouseHistory.setSpec(" ");
                warehouseHistory.setUnit("双");
                warehouseHistory.setPrice(6);
                warehouseHistory.setNum(1000);
                warehouseHistory.setTotalMoney(6000);
            }else if(i==1){
                warehouseHistory.setCargoName("高压手套");
                warehouseHistory.setCategoryName("劳保用品");
                warehouseHistory.setSpec(" ");
                warehouseHistory.setUnit("双");
                warehouseHistory.setPrice(6);
                warehouseHistory.setNum(2000);
                warehouseHistory.setTotalMoney(12000);
            }else if(i==2){
                warehouseHistory.setCargoName("安全帽");
                warehouseHistory.setCategoryName("劳保用品");
                warehouseHistory.setSpec(" ");
                warehouseHistory.setUnit("顶");
                warehouseHistory.setPrice(17);
                warehouseHistory.setNum(500);
                warehouseHistory.setTotalMoney(8500);
            }else if(i==3){
                warehouseHistory.setCargoName("电缆挂钩");
                warehouseHistory.setCategoryName("电缆挂钩");
                warehouseHistory.setSpec("Φ28");
                warehouseHistory.setUnit("个");
                warehouseHistory.setPrice(1.18);
                warehouseHistory.setNum(300);
                warehouseHistory.setTotalMoney(354);
            }else if(i==4){
                warehouseHistory.setCargoName("电缆挂钩");
                warehouseHistory.setCategoryName("电缆挂钩");
                warehouseHistory.setSpec("Φ68");
                warehouseHistory.setUnit("个");
                warehouseHistory.setPrice(1.58);
                warehouseHistory.setNum(200);
                warehouseHistory.setTotalMoney(316);
            }else if(i==5){
                warehouseHistory.setCargoName("电缆挂钩");
                warehouseHistory.setCategoryName("电缆挂钩");
                warehouseHistory.setSpec("Φ80");
                warehouseHistory.setUnit("个");
                warehouseHistory.setPrice(1.78);
                warehouseHistory.setNum(200);
                warehouseHistory.setTotalMoney(356);
            }else if(i==6){
                warehouseHistory.setCargoName("LED灯");
                warehouseHistory.setCategoryName("照明灯具");
                warehouseHistory.setSpec("220V");
                warehouseHistory.setUnit("台");
                warehouseHistory.setPrice(195);
                warehouseHistory.setNum(1);
                warehouseHistory.setTotalMoney(195);
            }else if(i==7){
                warehouseHistory.setCargoName("T8灯管");
                warehouseHistory.setCategoryName("照明灯具");
                warehouseHistory.setSpec(" ");
                warehouseHistory.setUnit("个");
                warehouseHistory.setPrice(21);
                warehouseHistory.setNum(20);
                warehouseHistory.setTotalMoney(420);
            }else if(i==8){
                warehouseHistory.setCargoName("顶灯");
                warehouseHistory.setCategoryName("照明灯具");
                warehouseHistory.setSpec("30*40");
                warehouseHistory.setUnit("台");
                warehouseHistory.setPrice(39);
                warehouseHistory.setNum(1);
                warehouseHistory.setTotalMoney(39);
            }else if(i==9){
                warehouseHistory.setCargoName("灯带");
                warehouseHistory.setCategoryName("照明灯具");
                warehouseHistory.setSpec(" ");
                warehouseHistory.setUnit("卷");
                warehouseHistory.setPrice(600);
                warehouseHistory.setNum(2);
                warehouseHistory.setTotalMoney(1200);
            }else if(i==10){
                warehouseHistory.setCargoName("小红灯");
                warehouseHistory.setCategoryName("照明灯具");
                warehouseHistory.setSpec("220V");
                warehouseHistory.setUnit("台");
                warehouseHistory.setPrice(2);
                warehouseHistory.setNum(50);
                warehouseHistory.setTotalMoney(100);
            }else if(i==11){
                warehouseHistory.setCargoName("灯管");
                warehouseHistory.setCategoryName("照明灯具");
                warehouseHistory.setSpec(" ");
                warehouseHistory.setUnit("个");
                warehouseHistory.setPrice(2);
                warehouseHistory.setNum(20);
                warehouseHistory.setTotalMoney(40);
            }
            list.add(warehouseHistory);
        }

        return jqgridUtil.getJson(list, pageNo, 11 , 10);
    }
}
